package com.pig4cloud.pig.common.core.util;


import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;

import java.lang.management.ManagementFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * 时间工具类
 *
 * @author ruoyi
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils{

	public static String YYYY = "yyyy";

	public static String YYYY_MM = "yyyy-MM";

	public static String YYYYMM = "yyyyMM";

	public static String YYYY_MM_DD = "yyyy-MM-dd";

	public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

	public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

	public static String YYYY__MM__DD = "yyyy/MM/dd";

	public static String YYYY__MM__DD__HH__MM__SS = "yyyy/MM/dd HH:mm:ss";

	public static String YYYYMMDD = "yyyy年MM月dd日";

	private final static SimpleDateFormat sdfSimpleTime = new SimpleDateFormat("HH:mm:ss");

	public final static SimpleDateFormat sdfMonthSimple = new SimpleDateFormat("yyyyMM");

	private static String[] parsePatterns = {
			"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
			"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
			"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};

	private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");


	/**
	 * 获取当前Date型日期
	 *
	 * @return Date() 当前日期
	 */
	public static Date getNowDate() {
		return new Date();
	}



	public  static Date getDateTimeByDayCountBefore(int days){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.DAY_OF_MONTH,days);
		calendar.set(Calendar.HOUR_OF_DAY,0);
		calendar.set(Calendar.MINUTE,0);
		calendar.set(Calendar.SECOND,0);
		Date dateTime = calendar.getTime();
		return dateTime;
	}

	/**
	 * 日期型字符串转化为日期 格式
	 */
	public static Date parseDate(Object str) {
		if (str == null) {
			return null;
		}
		try {
			return parseDate(str.toString(), parsePatterns);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 获取当前月份的 最后 、 第一天
	 *
	 * @param month
	 * @return
	 */
	public static Date getDayOfMonth(int month, int isLast, int lastDay) {
		Date ret = null;

		//当月一号
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar1 = Calendar.getInstance();
		calendar1.set(Calendar.MONTH, month);
		if (lastDay > 0) {
			calendar1.set(Calendar.DAY_OF_MONTH, lastDay);
		} else {
			calendar1.set(Calendar.DAY_OF_MONTH, 1);
		}
		calendar1.set(Calendar.HOUR_OF_DAY, 0);
		calendar1.set(Calendar.MINUTE, 0);
		calendar1.set(Calendar.SECOND, 0);
		calendar1.set(Calendar.MILLISECOND, 0);
//		System.out.println("本月第一天: " + sdf.format(calendar1.getTime()));

		if (isLast == 0) {
			ret = calendar1.getTime();
		} else {
			//当月最后一天
			Calendar calendar2 = Calendar.getInstance();
			calendar2.set(Calendar.MONTH, month);
			int maxCurrentMonthDay = calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);
			if (lastDay > 0) {
				calendar2.set(Calendar.DAY_OF_MONTH, lastDay);
			} else {
				calendar2.set(Calendar.DAY_OF_MONTH, maxCurrentMonthDay);
			}
			calendar2.set(Calendar.HOUR_OF_DAY, 23);
			calendar2.set(Calendar.MINUTE, 59);
			calendar2.set(Calendar.SECOND, 59);
			calendar1.set(Calendar.MILLISECOND, 999);
//			System.out.println("本月最后一天: "+sdf.format(calendar2.getTime()));
			ret = calendar2.getTime();
		}
		return ret;
	}


	/**
	 * 将日期格式 转换成  字符串格式
	 * @param date
	 * @return
	 */
	public static String date2Str(Date date,String format) {
		SimpleDateFormat sdfTimes = new SimpleDateFormat(format);
		return sdfTimes.format(date);
	}

	public static String getYearMonthTime(Date date)
	{
		return dateTimeNow(YYYY_MM,date);
	}


	public static String dateTimeNow(final String format,Date date)
	{
		return parseDateToStr(format, date);
	}


	/**
	 *  获取前几个月或者后几个月
	 * @param month  前几个月 用负数   后几个月 用正数
	 * @return
	 */
	public static Map<String,Object> getMonthBy(int month){
		Map<String,Object> map = new HashMap<>();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
		Date date = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, month); //设置为前3月
		date = calendar.getTime();
		int yearNum = calendar.get(Calendar.YEAR);
		int montNum = calendar.get(Calendar.MONTH);
		String defaultStartDate = simpleDateFormat.format(date); //格式化前month月的时间
		map.put("month_num",montNum);
		map.put("beginTime",defaultStartDate + "-01 00:00:00");
		map.put("endTime",getLastDayOfMonth(yearNum,montNum+1) + " 23:59:59");
		return map;
	}



	/**
	 * 以年为单位获取 每个月的 日期范围
	 * @return
	 */
	public static List<Map<String,Object>> getDateTimeByMonth(int year){
		List<Map<String,Object>> list=  new ArrayList<>();
		for (int i = 0; i < 12; i++){
			Map<String,Object> map = new HashMap<>();
//            SimpleDateFormat sdf = new SimpleDateFormat("MM");
//            String format = sdf.format(new Date());
//            int month = Integer.parseInt(format);
//            System.out.println(month);
			String firstDayOfMonth = getFirstDayOfMonth(year,i + 1);
//            System.out.println(month+"月第一天："+firstDayOfMonth);
			String lastDayOfMonth = getLastDayOfMonth(year,i + 1);
//            System.out.println(month+"月的最后一天:"+ lastDayOfMonth);

			map.put("month",i + 1);
			map.put("beginDate",firstDayOfMonth);
			map.put("endDate",lastDayOfMonth);
			list.add(map);
		}
		return list;
	}




	/**
	 * 以年为单位获取 每个月的 日期范围
	 * @return
	 */
	public static List<Map<String,Object>> getDateTimeByMonth(){
		List<Map<String,Object>> list=  new ArrayList<>();
		for (int i = 0; i < 12; i++){
			Map<String,Object> map = new HashMap<>();
//            SimpleDateFormat sdf = new SimpleDateFormat("MM");
//            String format = sdf.format(new Date());
//            int month = Integer.parseInt(format);
//            System.out.println(month);
			String firstDayOfMonth = getFirstDayOfMonth(i + 1);
//            System.out.println(month+"月第一天："+firstDayOfMonth);
			String lastDayOfMonth = getLastDayOfMonth(i + 1);
//            System.out.println(month+"月的最后一天:"+ lastDayOfMonth);

			map.put("month",i + 1);
			map.put("beginDate",firstDayOfMonth);
			map.put("endDate",lastDayOfMonth);
			list.add(map);
		}
		return list;
	}


	/**
	 * 获取当前月第一天
	 * @param year
	 * @param month
	 * @return
	 */
	public static String getFirstDayOfMonth(int year, int month) {
		Calendar calendar = Calendar.getInstance();
		// 设置月份
		calendar.set(Calendar.YEAR,year);
		// 设置月份
		calendar.set(Calendar.MONTH, month - 1);
		// 获取某月最小天数
		int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
		// 设置日历中月份的最小天数
		calendar.set(Calendar.DAY_OF_MONTH, firstDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String firstDayDate = sdf.format(calendar.getTime());//+" 00:00:00";
		return firstDayDate;
	}



	/**
	 * 获取当前月第一天
	 * @param month
	 * @return
	 */
	public static String getFirstDayOfMonth(int month) {
		Calendar calendar = Calendar.getInstance();
		// 设置月份
		calendar.set(Calendar.MONTH, month - 1);
		// 获取某月最小天数
		int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
		// 设置日历中月份的最小天数
		calendar.set(Calendar.DAY_OF_MONTH, firstDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String firstDayDate = sdf.format(calendar.getTime());//+" 00:00:00";
		return firstDayDate;
	}


	/**
	 * 获取YYYY-MM-DD HH:mm:ss格式
	 * @return
	 */
	public static String getSimpleTime(Date date) {
		return sdfSimpleTime.format(date);
	}

	/**
	 * 获取YYYY-MM-DD格式
	 * @return
	 */
	public static String getDayByDate(Date date) {
		return sdfDay.format(date);
	}


	/**
	 * 获取当前月最后一天
	 * @param month
	 * @return
	 */
	public static String getLastDayOfMonth(int year, int month) {
		Calendar calendar = Calendar.getInstance();
		// 设置月份
		calendar.set(Calendar.YEAR,year);
		// 设置月份
		calendar.set(Calendar.MONTH, month - 1);
		// 获取某月最大天数
		int lastDay = 0;
		//2月的平年瑞年天数
		if(month==2) {
			// 这个api在计算2020年2月的过程中有问题
			lastDay = calendar.getLeastMaximum(Calendar.DAY_OF_MONTH);
		}else {
			lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		}
		// 设置日历中月份的最大天数
		calendar.set(Calendar.DAY_OF_MONTH, lastDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String lastDayDate = sdf.format(calendar.getTime());//+" 23:59:59";
		return lastDayDate;
	}


	/**
	 * 获取yyyyMMddHHmmss格式
	 * @return
	 */
	public static String getMonthStr(Date date) {
		return sdfMonthSimple.format(date);
	}



	public static long getTimestamp(int hour) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		if (hour > 0) {
			calendar.add(Calendar.HOUR, hour);
		}
		long timestamp = calendar.getTime().getTime() / 1000;
		return timestamp;
	}

	public static Date getDateByHour(int hour) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		if (hour > 0) {
			calendar.add(Calendar.HOUR, hour);
		}
		return calendar.getTime();
	}


	/**
	 *  获取多少秒之后的时间
	 * @return
	 */
	public static Date getAfterSecondsByOld(Date date,int seconds){
		Calendar canlendar = Calendar.getInstance(); // java.util包
		canlendar.setTime(date);
		canlendar.add(Calendar.SECOND,seconds);
		return canlendar.getTime();
	}

	/**
	 * 获取当前日期, 默认格式为yyyy-MM-dd
	 *
	 * @return String
	 */
	public static String getDate() {
		return dateTimeNow(YYYY_MM_DD);
	}

	/**
	 * 获取当前日期, 默认格式为yyyy-MM-dd
	 *
	 * @return String
	 */
	public static String getDate(Date date) {
		return dateTimeNow(date,YYYY_MM_DD);
	}

	public static final String getTime() {
		return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
	}

	public static final String getTime(Date date) {
		return dateTimeNow(date, YYYY_MM_DD_HH_MM_SS);
	}

	public static final String getLocalDateTime(LocalDateTime date) {
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS);
		return dtf.format(date);
	}

	public static final String getLocalDateTime(LocalDateTime date, String formate) {
		if (date == null) {
			return null;
		}
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(formate);
		return dtf.format(date);
	}

	public static String getYear()
	{
		return dateTimeNow(YYYY);
	}

	public static final String dateTimeNow() {
		return dateTimeNow(YYYYMMDDHHMMSS);
	}

	public static final String dateTimeNow(final String format) {
		return parseDateToStr(format, new Date());
	}

	public static final String dateTimeNow(Date date, final String format) {
		return parseDateToStr(format, date);
	}


	public static final String dateTime(final Date date) {
		return parseDateToStr(YYYY_MM_DD, date);
	}

	public static final String parseDateToStr(final String format, final Date date) {
		return new SimpleDateFormat(format).format(date);
	}


	/**
	 * 获取当前月最后一天
	 * @param month
	 * @return
	 */
	public static String getLastDayOfMonth(int month) {
		Calendar calendar = Calendar.getInstance();
		// 设置月份
		calendar.set(Calendar.MONTH, month - 1);
		// 获取某月最大天数
		int lastDay = 0;
		//2月的平年瑞年天数
		if(month==2) {
			// 这个api在计算2020年2月的过程中有问题
			lastDay = calendar.getLeastMaximum(Calendar.DAY_OF_MONTH);
		}else {
			lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		}
		// 设置日历中月份的最大天数
		calendar.set(Calendar.DAY_OF_MONTH, lastDay);
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String lastDayDate = sdf.format(calendar.getTime());//+" 23:59:59";
		return lastDayDate;
	}


	public static final Date dateTime(final String format, final String ts) {
		try {
			return new SimpleDateFormat(format).parse(ts);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 日期路径 即年/月/日 如2018/08/08
	 */
	public static final String datePath() {
		Date now = new Date();
//		return sdfDay.format(now, "yyyy/MM/dd");
		return new SimpleDateFormat("yyyy/MM/dd").format(now);
	}

	/**
	 * 日期路径 即年/月/日 如20180808
	 */
	public static final String dateTime() {
		Date now = new Date();
//		return DateFormatUtils.format(now, "yyyyMMdd");
		return new SimpleDateFormat("yyyyMMdd").format(now);
	}


	/**
	 * 获取服务器启动时间
	 */
	public static Date getServerStartDate() {
		long time = ManagementFactory.getRuntimeMXBean().getStartTime();
		return new Date(time);
	}

	/**
	 * 计算两个时间差
	 */
	public static String getDatePoor(Date endDate, Date nowDate) {
		long nd = 1000 * 24 * 60 * 60;
		long nh = 1000 * 60 * 60;
		long nm = 1000 * 60;
		// long ns = 1000;
		// 获得两个时间的毫秒时间差异
		long diff = endDate.getTime() - nowDate.getTime();
		// 计算差多少天
		long day = diff / nd;
		// 计算差多少小时
		long hour = diff % nd / nh;
		// 计算差多少分钟
		long min = diff % nd % nh / nm;
		// 计算差多少秒//输出结果
		// long sec = diff % nd % nh % nm / ns;
		return day + "天" + hour + "小时" + min + "分钟";
	}

	public static Date ConvertDateByformatFromExcel(String date) {
		if (StrUtil.isBlank(date)) {
			return null;
		}
		String format = "yyyy-M-d";
		if (date.contains(":")) {
			if (date.split(":").length == 2) {
				format = "yyyy-M-d H:m";
			} else {
				format = "yyyy-M-d H:m:s";
			}
		}
		if (date.contains(".")) {
			format = format.replaceAll("-", ".");
			String[] dateArr = date.split("\\.");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		} else if (date.contains("/")) {
			format = format.replaceAll("-", "/");
			String[] dateArr = date.split("/");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		} else {
			String[] dateArr = date.split("-");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		}
		DateFormat fmt = new SimpleDateFormat(format);
		fmt.setLenient(false);
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			throw new IllegalArgumentException("时间格式错误:" + date);
		}
	}

	public static LocalDateTime ConvertLocalDateByformatFromExcel(String date) {
		if (StrUtil.isBlank(date)) {
			return null;
		}
		String format = "yyyy-M-d HH:mm:ss";
		if (date.contains(":")) {
			//只有分时的
			if (date.split(":").length == 2) {
				format = "yyyy-M-d HH:mm";
			}
		} else {
			date += " 00:00:00";
		}
		if (date.contains(".")) {
			format = format.replaceAll("-", ".");
			String[] dateArr = date.split("\\.");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		} else if (date.contains("/")) {
			format = format.replaceAll("-", "/");
			String[] dateArr = date.split("/");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		} else {
			String[] dateArr = date.split("-");
			if (dateArr.length > 0) {
				if (dateArr[0].length() > 4) {
					throw new IllegalArgumentException("时间格式错误:" + date);
				}
			}
		}
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(format);
		try {
			return LocalDateTime.parse(date, fmt);
		} catch (Exception e) {
			e.printStackTrace();
			throw new IllegalArgumentException("时间格式错误:" + date);
		}
	}

	public static LocalDateTime addDay(LocalDateTime dateTime, int days) {
		if (dateTime != null) {
			return dateTime.plusDays(days);
		}
		return null;
	}


	/**
	 * 两个时间相差距离多少天多少小时多少分多少秒
	 *
	 * @param date1 时间参数 1 格式：1990-01-01 12:00:00
	 * @param date2 时间参数 2 格式：2009-01-01 12:00:00
	 * @return long[] 返回值为：{天, 时, 分, 秒}
	 */
	public static long[] getDistanceTimes(Date date1, Date date2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long day = 0;
		long hour = 0;
		long min = 0;
		long sec = 0;
		try {
			long time1 = date1.getTime();
			long time2 = date2.getTime();
			long diff;
			if (time1 < time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			day = diff / (24 * 60 * 60 * 1000);
			hour = (diff / (60 * 60 * 1000) - day * 24);
			min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
			sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		} catch (Exception e) {
			e.printStackTrace();
		}
		long[] times = {day, hour, min, sec};
		return times;
	}

	public static int getDistanceDays(String str1, String str2) throws Exception {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date one;
		Date two;
		int day = 0;
		try {
			one = df.parse(str1);
			two = df.parse(str2);
			long time1 = one.getTime();
			long time2 = two.getTime();
			long diff;
			if (time1 < time2) {
				diff = time2 - time1;
			} else {
				diff = time1 - time2;
			}
			long days = diff / (1000 * 60 * 60 * 24);
			day = new Long(days).intValue();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return day;
	}


	public static Date fomatDate(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static Date fomatDateTime(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}


	/**
	 * 格式化日期
	 *
	 * @return
	 */
	public static Date fomatTime(String date) {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return fmt.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 获取YYYY-MM-DD格式
	 *
	 * @return
	 */
	public static String getDay() {
		return sdfDay.format(new Date());
	}

	public static Date getDateByMinuts(Date date, int minuts) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		if (minuts > 0) {
			calendar.add(Calendar.MINUTE, minuts);
		}
		return calendar.getTime();
	}


	/**
	 * Date 转 LocalDateTime
	 *
	 * @param date
	 * @return
	 */
	public static LocalDateTime dataToLocalDateTime(Date date) {
		if (date == null) {
			return null;
		}
		Instant instant = date.toInstant();
		ZoneId zoneId = ZoneId.systemDefault();
		return instant.atZone(zoneId).toLocalDateTime();
	}

	/**
	 * LocalDateTime 转 Date
	 *
	 * @param localDateTime
	 * @return
	 */
	public static Date localDateTimeToDate(LocalDateTime localDateTime) {
		if (localDateTime == null) {
			return null;
		}
		ZoneId zoneId = ZoneId.systemDefault();
		ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
		return Date.from(zonedDateTime.toInstant());
	}


	/**
	 * 当天起始时间
	 *
	 * @param format "yyyy-MM-dd HH:mm:ss"
	 * @return 如：2021-11-11 00:00:00
	 */
	public static String nowBegin(String format) {
		return LocalDateTimeUtil.format(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), format);
	}

	/**
	 * 当日剩余秒数
	 *
	 * @return
	 */
	public static long getDayRemainingSecond() {
		LocalDate now = LocalDate.now();
		LocalDateTime of = LocalDateTime.of(now, LocalTime.MIN);
		LocalDateTime localDateTime = of.plusDays(1);
		return TimeUnit.NANOSECONDS.toSeconds(Duration.between(LocalDateTime.now(), localDateTime).toNanos());
	}

	///////

	/**
	 * 当前时间
	 *
	 * @return
	 */
	public static LocalDateTime now() {
		return LocalDateTime.now();
	}

	/**
	 * Date 转 LocalDateTime
	 *
	 * @return
	 */
	public static LocalDateTime convert(Date date) {
		return LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
	}

	/**
	 * LocalDateTime 转 Date
	 *
	 * @return
	 */
	public static Date convert(LocalDateTime localDateTime) {
		return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
	}

	/**
	 * 今天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime todayStartTime() {
		return LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
	}

	/**
	 * 今天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime todayEndTime() {
		return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
	}

	/**
	 * 昨天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime yesterdayStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.DAYS), LocalTime.MIN);
	}

	/**
	 * 昨天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime yesterdayEndTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.DAYS), LocalTime.MAX);
	}

	/**
	 * 最近7天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime last7DaysStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(6L, ChronoUnit.DAYS), LocalTime.MIN);
	}

	/**
	 * 最近三天
	 *
	 * @return
	 */
	public static LocalDateTime last3DaysStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(3L, ChronoUnit.DAYS), LocalTime.MIN);
	}

	/**
	 * 最近7天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime last7DaysEndTime() {
		return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
	}

	/**
	 * 最近30天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime last30DaysStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(29L, ChronoUnit.DAYS), LocalTime.MIN);
	}

	/**
	 * 最近30天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime last30DaysEndTime() {
		return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
	}

	/**
	 * 最近一年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime last1YearStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).plus(1L, ChronoUnit.DAYS), LocalTime.MIN);
	}

	/**
	 * 最近一年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime last1YearEndTime() {
		return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
	}

	/**
	 * 本周开始时间
	 *
	 * @return
	 */
	public static LocalDateTime weekStartTime() {
		LocalDate now = LocalDate.now();
		return LocalDateTime.of(now.minusDays(now.getDayOfWeek().getValue() - 1), LocalTime.MIN);
	}

	/**
	 * 本周结束时间
	 *
	 * @return
	 */
	public static LocalDateTime weekEndTime() {
		LocalDate now = LocalDate.now();
		return LocalDateTime.of(now.plusDays(7 - now.getDayOfWeek().getValue()), LocalTime.MAX);
	}

	/**
	 * 本月开始时间
	 *
	 * @return
	 */
	public static LocalDateTime monthStartTime() {
		return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
	}

	/**
	 * 本月结束时间
	 *
	 * @return
	 */
	public static LocalDateTime monthEndTime() {
		return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
	}

	/**
	 * 本季度开始时间
	 *
	 * @return
	 */
	public static LocalDateTime quarterStartTime() {
		LocalDate now = LocalDate.now();
		Month month = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
		return LocalDateTime.of(LocalDate.of(now.getYear(), month, 1), LocalTime.MIN);
	}

	/**
	 * 本季度结束时间
	 *
	 * @return
	 */
	public static LocalDateTime quarterEndTime() {
		LocalDate now = LocalDate.now();
		Month month = Month.of(now.getMonth().firstMonthOfQuarter().getValue()).plus(2L);
		return LocalDateTime.of(LocalDate.of(now.getYear(), month, month.length(now.isLeapYear())), LocalTime.MAX);
	}

	/**
	 * 本半年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime halfYearStartTime() {
		LocalDate now = LocalDate.now();
		Month month = (now.getMonthValue() > 6) ? Month.JULY : Month.JANUARY;
		return LocalDateTime.of(LocalDate.of(now.getYear(), month, 1), LocalTime.MIN);
	}

	/**
	 * 本半年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime halfYearEndTime() {
		LocalDate now = LocalDate.now();
		Month month = (now.getMonthValue() > 6) ? Month.DECEMBER : Month.JUNE;
		return LocalDateTime.of(LocalDate.of(now.getYear(), month, month.length(now.isLeapYear())), LocalTime.MAX);
	}

	/**
	 * 本年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime yearStartTime() {
		return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
	}

	/**
	 * 本年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime yearEndTime() {
		return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
	}

	/**
	 * 上周开始时间
	 *
	 * @return
	 */
	public static LocalDateTime lastWeekStartTime() {
		LocalDate lastWeek = LocalDate.now().minus(1L, ChronoUnit.WEEKS);
		return LocalDateTime.of(lastWeek.minusDays(lastWeek.getDayOfWeek().getValue() - 1), LocalTime.MIN);
	}

	/**
	 * 上周结束时间
	 *
	 * @return
	 */
	public static LocalDateTime lastWeekEndTime() {
		LocalDate lastWeek = LocalDate.now().minus(1L, ChronoUnit.WEEKS);
		return LocalDateTime.of(lastWeek.plusDays(7 - lastWeek.getDayOfWeek().getValue()), LocalTime.MAX);
	}

	/**
	 * 上月开始时间
	 *
	 * @return
	 */
	public static LocalDateTime lastMonthStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
	}

	/**
	 * 上月结束时间
	 *
	 * @return
	 */
	public static LocalDateTime lastMonthEndTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
	}

	/**
	 * 上季度开始时间
	 *
	 * @return
	 */
	public static LocalDateTime lastQuarterStartTime() {
		LocalDate now = LocalDate.now();
		Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
		Month firstMonthOfLastQuarter = firstMonthOfQuarter.minus(3L);
		int yearOfLastQuarter = firstMonthOfQuarter.getValue() < 4 ? now.getYear() - 1 : now.getYear();
		return LocalDateTime.of(LocalDate.of(yearOfLastQuarter, firstMonthOfLastQuarter, 1), LocalTime.MIN);
	}

	/**
	 * 上季度结束时间
	 *
	 * @return
	 */
	public static LocalDateTime lastQuarterEndTime() {
		LocalDate now = LocalDate.now();
		Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
		Month firstMonthOfLastQuarter = firstMonthOfQuarter.minus(1L);
		int yearOfLastQuarter = firstMonthOfQuarter.getValue() < 4 ? now.getYear() - 1 : now.getYear();
		return LocalDateTime.of(LocalDate.of(yearOfLastQuarter, firstMonthOfLastQuarter, firstMonthOfLastQuarter.maxLength()), LocalTime.MAX);
	}

	/**
	 * 上半年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime lastHalfYearStartTime() {
		LocalDate now = LocalDate.now();
		int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() : now.getYear() - 1;
		Month firstMonthOfLastHalfYear = (now.getMonthValue() > 6) ? Month.JANUARY : Month.JULY;
		return LocalDateTime.of(LocalDate.of(lastHalfYear, firstMonthOfLastHalfYear, 1), LocalTime.MIN);
	}

	/**
	 * 上半年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime lastHalfYearEndTime() {
		LocalDate now = LocalDate.now();
		int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() : now.getYear() - 1;
		Month lastMonthOfLastHalfYear = (now.getMonthValue() > 6) ? Month.JUNE : Month.DECEMBER;
		return LocalDateTime.of(LocalDate.of(lastHalfYear, lastMonthOfLastHalfYear, lastMonthOfLastHalfYear.maxLength()), LocalTime.MAX);
	}

	/**
	 * 上一年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime lastYearStartTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
	}

	/**
	 * 上一年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime lastYearEndTime() {
		return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
	}

	/**
	 * 下周开始时间
	 *
	 * @return
	 */
	public static LocalDateTime nextWeekStartTime() {
		LocalDate nextWeek = LocalDate.now().plus(1L, ChronoUnit.WEEKS);
		return LocalDateTime.of(nextWeek.minusDays(nextWeek.getDayOfWeek().getValue() - 1), LocalTime.MIN);
	}

	/**
	 * 下周结束时间
	 *
	 * @return
	 */
	public static LocalDateTime nextWeekEndTime() {
		LocalDate nextWeek = LocalDate.now().plus(1L, ChronoUnit.WEEKS);
		return LocalDateTime.of(nextWeek.plusDays(7 - nextWeek.getDayOfWeek().getValue()), LocalTime.MAX);
	}

	/**
	 * 下月开始时间
	 *
	 * @return
	 */
	public static LocalDateTime nextMonthStartTime() {
		return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
	}

	/**
	 * 下月结束时间
	 *
	 * @return
	 */
	public static LocalDateTime nextMonthEndTime() {
		return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
	}

	/**
	 * 下季度开始时间
	 *
	 * @return
	 */
	public static LocalDateTime nextQuarterStartTime() {
		LocalDate now = LocalDate.now();
		Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
		Month firstMonthOfNextQuarter = firstMonthOfQuarter.plus(3L);
		int yearOfNextQuarter = firstMonthOfQuarter.getValue() > 9 ? now.getYear() + 1 : now.getYear();
		return LocalDateTime.of(LocalDate.of(yearOfNextQuarter, firstMonthOfNextQuarter, 1), LocalTime.MIN);
	}

	/**
	 * 下季度结束时间
	 *
	 * @return
	 */
	public static LocalDateTime nextQuarterEndTime() {
		LocalDate now = LocalDate.now();
		Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
		Month firstMonthOfNextQuarter = firstMonthOfQuarter.plus(5L);
		int yearOfNextQuarter = firstMonthOfQuarter.getValue() > 9 ? now.getYear() + 1 : now.getYear();
		return LocalDateTime.of(LocalDate.of(yearOfNextQuarter, firstMonthOfNextQuarter, firstMonthOfNextQuarter.maxLength()), LocalTime.MAX);
	}

	/**
	 * 上半年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime nextHalfYearStartTime() {
		LocalDate now = LocalDate.now();
		int nextHalfYear = (now.getMonthValue() > 6) ? now.getYear() + 1 : now.getYear();
		Month firstMonthOfNextHalfYear = (now.getMonthValue() > 6) ? Month.JANUARY : Month.JULY;
		return LocalDateTime.of(LocalDate.of(nextHalfYear, firstMonthOfNextHalfYear, 1), LocalTime.MIN);
	}

	/**
	 * 上半年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime nextHalfYearEndTime() {
		LocalDate now = LocalDate.now();
		int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() + 1 : now.getYear();
		Month lastMonthOfNextHalfYear = (now.getMonthValue() > 6) ? Month.JUNE : Month.DECEMBER;
		return LocalDateTime.of(LocalDate.of(lastHalfYear, lastMonthOfNextHalfYear, lastMonthOfNextHalfYear.maxLength()), LocalTime.MAX);
	}

	/**
	 * 下一年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime nextYearStartTime() {
		return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
	}

	/**
	 * 下一年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime nextYearEndTime() {
		return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
	}

	public static String getQuarterNo(LocalDateTime localDate) {
		int monthValue = localDate.getMonthValue();
		if (monthValue <= 3) {
			return "一";
		} else if (monthValue <= 6) {
			return "二";
		} else if (monthValue <= 9) {
			return "三";
		} else {
			return "四";
		}
	}

	/**
	 * 入参日期所属季度开始时间
	 *
	 * @return
	 */
	public static LocalDateTime quarterStartTime(LocalDate date) {
		Month month = Month.of(date.getMonth().firstMonthOfQuarter().getValue());
		return LocalDateTime.of(LocalDate.of(date.getYear(), month, 1), LocalTime.MIN);
	}

	/**
	 * 入参日期所属季度结束时间
	 *
	 * @return
	 */
	public static LocalDateTime quarterEndTime(LocalDate date) {
		Month month = Month.of(date.getMonth().firstMonthOfQuarter().getValue()).plus(2L);
		return LocalDateTime.of(LocalDate.of(date.getYear(), month, month.length(date.isLeapYear())), LocalTime.MAX);
	}

	/**
	 * 本年开始时间
	 *
	 * @return
	 */
	public static LocalDateTime thisYearStartTime(LocalDate date) {

		return LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
	}

	/**
	 * 本年结束时间
	 *
	 * @return
	 */
	public static LocalDateTime thisYearEndTime(LocalDate date) {
		return LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
	}

	/**
	 * 某天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime thisTodayStartTime(LocalDate date) {
		return LocalDateTime.of(date, LocalTime.MIN);
	}

	/**
	 * 某天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime thisTodayEndTime(LocalDate date) {
		return LocalDateTime.of(date, LocalTime.MAX);
	}

	/**
	 * 某天开始时间
	 *
	 * @return
	 */
	public static String getStartTime(LocalDate date) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS);
		LocalDateTime localDateTime = LocalDateTime.of(date, LocalTime.MIN);
		return localDateTime.format(fmt);
	}

	/**
	 * 某天结束时间
	 *
	 * @return
	 */
	public static String getEndTime(LocalDate date) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS);
		LocalDateTime localDateTime = LocalDateTime.of(date, LocalTime.MAX);
		return localDateTime.format(fmt);
	}

	/**
	 * 上一天开始时间
	 *
	 * @return
	 */
	public static LocalDateTime thisLastDayStartTime(LocalDate date) {
		return LocalDateTime.of(date, LocalTime.MIN).minusDays(1);
	}

	/**
	 * 上一天结束时间
	 *
	 * @return
	 */
	public static LocalDateTime thisLastDayEndTime(LocalDate date) {
		return LocalDateTime.of(date, LocalTime.MAX).minusDays(1);
	}

	/**
	 * 本月开始时间
	 *
	 * @return
	 */
	public static LocalDateTime thisMonthStartTime(LocalDate date) {
		return LocalDateTime.of(date.with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
	}

	/**
	 * 本月结束时间
	 *
	 * @return
	 */
	public static LocalDateTime thisMonthEndTime(LocalDate date) {
		return LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
	}

	/**
	 * 本周开始时间
	 *
	 * @return
	 */
	public static LocalDateTime thisWeekStartTime(LocalDate date) {

		return LocalDateTime.of(date.minusDays(date.getDayOfWeek().getValue() - 1), LocalTime.MIN);
	}

	/**
	 * 本周结束时间
	 *
	 * @return
	 */
	public static LocalDateTime thisWeekEndTime(LocalDate date) {

		return LocalDateTime.of(date.plusDays(7 - date.getDayOfWeek().getValue()), LocalTime.MAX);
	}

	/**
	 * 得到 天数 的时间  （负数查前几天的  正数 查后几天的）
	 *
	 * @param days
	 * @param isLimitTime 0 - 时分秒不动 1 - 取0点时间  2 - 取23点59分59秒 时间
	 * @return
	 */
	public static Date getDateByDays(int days, int isLimitTime) {
		Calendar canlendar = Calendar.getInstance(); // java.util包
		canlendar.add(Calendar.DATE, days); // 日期减 如果不够减会将月变动
		if (isLimitTime == 1) {
			canlendar.set(Calendar.HOUR_OF_DAY, 0);
			canlendar.set(Calendar.MINUTE, 0);
			canlendar.set(Calendar.SECOND, 0);
		} else if (isLimitTime == 2) {
			canlendar.set(Calendar.HOUR_OF_DAY, 23);
			canlendar.set(Calendar.MINUTE, 59);
			canlendar.set(Calendar.SECOND, 59);
		}
		Date date = canlendar.getTime();
		return date;
	}

	/**
	 * 两个日期间隔天数
	 *
	 * @param start 开始时间
	 * @param end   结束时间
	 * @return
	 */
	public static long diffTimes(LocalDate start, LocalDate end) {
		Duration between = Duration.between(start.atStartOfDay(), end.atStartOfDay());
		return between.toDays();
	}

	/**
	 * 日期所属周
	 * 每年一号算第一周开始时间
	 *
	 * @return
	 */
	public static int getWeekNum(LocalDate date) {
		WeekFields wf = WeekFields.of(DayOfWeek.MONDAY, 1);
		return date.get(wf.weekOfYear());
	}

	/**
	 * 两个日期间隔时间描述
	 *
	 * @param start 开始时间
	 * @param end   结束时间
	 * @return
	 */
	public static String diffTimes(LocalDateTime start, LocalDateTime end) {
		Duration duration = Duration.between(start, end);
		long days = duration.toDays(); //相差的天数
		long hours = duration.toHours() % 24;//小时数
		String diff = days + "天 " + hours + "小时";
		return diff;
	}


	/**
	 * 本旬开始时间
	 *
	 * @return
	 */
	public static LocalDateTime tenDayStartTime() {
		int dayOfMonth = LocalDate.now().getDayOfMonth();
		if (dayOfMonth < 11) {
			//上旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
		} else if (dayOfMonth < 21) {
			//中旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(10), LocalTime.MIN);
		} else {
			//下旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(20), LocalTime.MIN);
		}
	}

	/**
	 * 本旬结束时间
	 *
	 * @return
	 */
	public static LocalDateTime tenDayEndTime() {
		int dayOfMonth = LocalDate.now().getDayOfMonth();
		if (dayOfMonth < 11) {
			//上旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(9), LocalTime.MAX);
		} else if (dayOfMonth < 21) {
			//中旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(19), LocalTime.MAX);
		} else {
			//下旬
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
		}


	}

	/**
	 * 半月开始时间
	 * @param date 日期  例如“2022-09”
	 * @param flag 1:上半月  2：下半月
	 * @return
	 */
	public static LocalDateTime halfMonthStartTime(String date, int flag) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");
		YearMonth ym = YearMonth.parse(date, fmt);
		LocalDate dt = ym.atEndOfMonth();
		if (flag == 1) {
			return LocalDateTime.of(dt.with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
		} else {
			return LocalDateTime.of(dt.with(TemporalAdjusters.firstDayOfMonth()).plusDays(15), LocalTime.MIN);
		}
	}

	/**
	 * 半月结束时间
	 * @param date 日期  例如“2022-09”
	 * @param flag 1:上半月  2：下半月
	 * @return
	 */
	public static LocalDateTime halfMonthEndTime(String date, int flag) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");
		YearMonth ym = YearMonth.parse(date, fmt);
		LocalDate dt = ym.atEndOfMonth();
		if (flag == 1) {
			return LocalDateTime.of(dt.with(TemporalAdjusters.firstDayOfMonth()).plusDays(14), LocalTime.MAX);
		} else {
			return LocalDateTime.of(dt.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
		}
	}

	/**
	 * 当前日期半月开始时间
	 * @return
	 */
	public static LocalDateTime halfMonthStartTime() {
		int dayOfMonth = LocalDate.now().getDayOfMonth();
		if (dayOfMonth < 16) {
			//上半月
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
		}  else {
			//下半月
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(15), LocalTime.MIN);
		}
	}

	/**
	 * 当前日期半月结束时间
	 * @return
	 */
	public static LocalDateTime halfMonthEndTime() {
		int dayOfMonth = LocalDate.now().getDayOfMonth();
		if (dayOfMonth < 16) {
			//上半月
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).plusDays(14), LocalTime.MAX);
		}  else {
			//下半月
			return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
		}
	}

	public static String getLocalDateMonth(LocalDate date) {
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(YYYYMM);
		return dtf.format(date);
	}

	public static LocalDate ConvertLocalDate(String date) {
		if (StrUtil.isBlank(date)) {
			return null;
		}
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(YYYY_MM_DD);
		try {
			return LocalDate.parse(date, fmt);
		} catch (Exception e) {
			e.printStackTrace();
			throw new IllegalArgumentException("时间格式错误:" + date);
		}
	}

	/**
	 * 某个时间增加指定个工作日
	 * @param date
	 * @param days
	 * @return
	 */
	public static LocalDateTime addWorkDays(LocalDateTime date, int days) {
		int addedDays = 0;
		while (addedDays < days) {
			date = date.plusDays(1);
			if (!(date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY)) {
				++addedDays;
			}
		}
		return date;
	}

	public static void main(String[] args) {
//		LocalDateTime now = LocalDateTime.now();
//		LocalDateTime localDateTime = now.plusDays(100).minusHours(2);
//		String s = diffTimes(now, localDateTime);
//		System.out.println(s);

//		System.out.println(tenDayStartTime());
//		System.out.println(tenDayEndTime());

//		System.out.println(halfMonthStartTime("2022-03",1));
//		System.out.println(halfMonthEndTime("2022-03",1));
//		System.out.println(halfMonthStartTime("2022-03",2));
//		System.out.println(halfMonthEndTime("2022-03",2));
//
//		System.out.println(halfMonthStartTime());
//		System.out.println(halfMonthEndTime());

//		System.out.println(getLocalDateMonth(LocalDate.now()));

		LocalDate date = LocalDate.now().minusDays(2);
		String localDateTime = getStartTime(date);
		String localDateTime1 = getEndTime(date);
		System.out.println(localDateTime);
		System.out.println(localDateTime1);


		LocalDate localDate = ConvertLocalDate("2022-01-27");
		System.out.println(localDate);

		LocalDateTime localDateTime2 = addWorkDays(LocalDateTime.now(), 4);
		System.out.println(localDateTime2);
	}
}
